import os
import sys

import math
def is_prime(num):
  if num<2:
    return False
  for i in range(2,int(math.sqrt(num))):
    if num%i==0:
      return False
  return True
def refind(n,s):
  for i in range(s):
    for p in range(int(math.sqrt(n)),1,-1):
      if is_prime(p) and n%p==0:
        n=((n//p)-1)*p
        break
      else:
        return -1
  return n

n=int(input())
int_value=refind(n,2)
if(int_value==-1):
  print('-1')
else:
  print({int_value})
